var t = require;
var e = module;
cc.Class({
    extends: cc.Component,
    properties: {
        mask: cc.Node,
        layout: cc.Layout,
        label: cc.Label,
        image: cc.Sprite,
        sound: cc.AudioSource,
        nodeLeft: cc.Node,
        nodeRight: cc.Node,
        soundTime: cc.Label
    },
    onLoad: function onLoad() {
        (this.TYPE_SOUND = "sound"), (this.TYPE_IMG = "image"), (this.TYPE_WORD = "word");
    },
    start: function start() {
        (this.isSelected = !1),
            (this.slined = null),
            this.init(),
            (this.defColor = this.mask.color.toHEX()),
            (this.isInTouch = !1);
    },
    onTouchStart: function onTouchStart(t) {
        (this.isInTouch = !0), this.slined || (this.touchCb && this.touchCb("onTouchStart", this, t));
    },
    onTouchMove: function onTouchMove(t) {
        this.slined || this.isSelected || (this.touchCb && this.touchCb("onTouchMove", this, t));
    },
    onTouchEnd: function onTouchEnd(t) {
        this.isInTouch &&
            ((this.isInTouch = !1),
            !this.slined && this.isSelected && this.touchCb && this.touchCb("onTouchEnd", this, t));
    },
    onTouchCancel: function onTouchCancel(t) {
        this.onTouchEnd(t);
    },
    selected: function selected() {
        this.slined ||
            this.isSelected ||
            ((this.isSelected = !0),
            (this.mask.color = this.mask.color.fromHEX("ffffff")),
            this.type == this.TYPE_SOUND && this.sound.play());
    },
    unselected: function unselected() {
        !this.slined &&
            this.isSelected &&
            ((this.isSelected = !1), (this.mask.color = this.mask.color.fromHEX(this.defColor)));
    },
    lined: function lined(t) {
        if (
            ((this.slined = t),
            (this.mask.color = this.mask.color.fromHEX(lGlobal.getNextWordBgColor())),
            (this.slined.mask.color = this.mask.color),
            "right" == this.leftOrRight)
        )
            try {
                this.sound && this.sound.clip && this.sound.play();
            } catch (e) {
                console.log("LcWord.js lined error:" + e);
            }
    },
    init: function init() {
        switch (
            ((this.label.node.active = !1), (this.image.node.active = !1), (this.sound.node.active = !1), this.type)
        ) {
            case this.TYPE_SOUND:
                this.sound.node.active = !0;
                break;
            case this.TYPE_IMG:
                this.image.node.active = !0;
                break;
            case this.TYPE_WORD:
                this.label.node.active = !0;
        }
        this.setContent(this.cname, this.leftOrRight);
    },
    setType: function setType(t, e, o, i) {
        (this.type = t),
            (this.cname = e),
            (this.leftOrRight = o),
            (this.touchCb = i),
            "left" == this.leftOrRight
                ? (this.nodeLineStart = this.nodeRight)
                : "right" == this.leftOrRight && (this.nodeLineStart = this.nodeLeft);
    },
    setContent: function setContent(t, e) {
        var o = this,
            i = lGlobal.modelBundles[lGlobal.curModel];
        if (i) {
            var n = cc.js.formatStr("data/%s/%s%s", t, e, "Word");
            i.load(n, cc.TextAsset, null, function (e, i) {
                e ? console.log(t + " 没有 Word") : (o.label.string = i.text);
            }),
                (n = cc.js.formatStr("data/%s/%s%s", t, e, "Img")),
                i.load(n, cc.SpriteFrame, null, function (e, i) {
                    e ? console.log(t + " 没有 Img") : (o.image.spriteFrame = i);
                }),
                (n = cc.js.formatStr("data/%s/%s%s", t, e, "Sound")),
                i.load(n, cc.AudioClip, null, function (e, i) {
                    e ? console.log(t + " 没有 Sound") : ((o.sound.clip = i), (o.soundLen = o.sound.clip.duration));
                });
        }
    },
    update: function update() {
        if (this.sound.node.active && this.sound.clip) {
            var t = this.sound.clip.duration,
                e = this.sound.getCurrentTime();
            if ((e < 0 && (e = 0), this.sound.isPlaying)) {
                var o = (t - e).toFixed(1);
                this.soundTime.string = "‘" + o + "s";
            } else {
                var i = t.toFixed(1);
                this.soundTime.string = "‘" + i + "s";
            }
        }
    }
});
